﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Eraile
using Microsoft.Xna.Framework;



namespace Plateformeur.Engine
{
    public class IntersectionInfo
    {
		/// <summary>
        /// Notre struct
        /// </summary>
		public struct CollisionInfo
		{
			public bool		mCollide;
			public Vector2	mDirection;
			public bool		mHitOnTop;
			public bool		mHitFromSide;
		}

        /// <summary>
        /// Variables
        /// </summary>
		public CollisionInfo	mCollideInfo;







        /// <summary>
        /// Constructeur
        /// </summary>
        /// <param name="gameObjectA"></param>
        /// <param name="gameObjectB"></param>
        public IntersectionInfo(GameObject gameObjectA, GameObject gameObjectB)
        {
			Rectangle tempRectA = new Rectangle( ( int )gameObjectA.Position.X, ( int )gameObjectA.Position.Y, gameObjectA.RenderRectangle.Width, gameObjectA.RenderRectangle.Height );
			Rectangle tempRectB = new Rectangle( ( int )gameObjectB.Position.X, ( int )gameObjectB.Position.Y, gameObjectB.RenderRectangle.Width, gameObjectB.RenderRectangle.Height );

			mCollideInfo.mCollide = tempRectA.Intersects( tempRectB );


			mCollideInfo.mDirection = new Vector2(   
													gameObjectA.Position.X - gameObjectB.Position.X, 
													gameObjectA.Position.Y - gameObjectB.Position.Y 
												);
			mCollideInfo.mHitOnTop = ( mCollideInfo.mDirection.Y < 0 );

        }

        public IntersectionInfo(GameObject gameObjectA, Rectangle pRect)
        {
            Rectangle tempRectA = new Rectangle((int)gameObjectA.Position.X, (int)gameObjectA.Position.Y, gameObjectA.RenderRectangle.Width, gameObjectA.RenderRectangle.Height);

            mCollideInfo.mCollide = tempRectA.Intersects(pRect);


            mCollideInfo.mDirection = new Vector2(
                                                    gameObjectA.Position.X - pRect.X,
                                                    gameObjectA.Position.Y - pRect.Y
                                                );
            mCollideInfo.mHitOnTop = (mCollideInfo.mDirection.Y < 0);

        }
    }
}
